﻿var finderUrl = "/CmsContent/Themes/Admin/Scripts/elfinder/elfinder.html"; // Default

function enableTinyMce(selector, height, width, elFinderUrl) {
	finderUrl = elFinderUrl;
	$(selector).tinymce({
		// General options
		theme: "advanced",
		plugins: "style,advimage,advlink,inlinepopups,media,contextmenu,paste,noneditable,nonbreaking,xhtmlxtras",
		height: height,
		width: width,
		remove_script_host: false,
		relative_urls: false,

		// Theme options
		theme_advanced_buttons1: "cut,copy,paste,pasteword,|,bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,blockquote,formatselect,|,undo,redo,|,link,unlink,anchor,image,media,|,cleanup,code",
		theme_advanced_buttons2: "",
		theme_advanced_buttons3: "",
		theme_advanced_toolbar_location: "top",
		theme_advanced_toolbar_align: "left",
		theme_advanced_statusbar_location: "bottom",
		theme_advanced_resizing: true,
		
		// File browser
		file_browser_callback: 'elFinderBrowser'
	});
}

function shutDownTinyMce() {
	$('textarea').tinymce().remove();
}

function elFinderBrowser(field_name, url, type, win) {
	tinyMCE.activeEditor.windowManager.open({
		file: finderUrl,
		title: 'elFinder 2.0',
		width: 900,
		height: 600,
		resizable: 'no',
		inline: 'yes',    // This parameter only has an effect if you use the inlinepopups plugin!
		popup_css: false, // Disable TinyMCE's default popup CSS
		close_previous: 'no'
	}, {
		window: win,
		input: field_name
	});
	return false;
}


